import React, {Component} from 'react'
import {inject} from 'mobx-react';
import {WeaBrowser, WeaDialog, WeaLocaleProvider, WeaRichText} from "ecCom";
import CubeLayout from "../../../../../govern/components/E9/cubeLayout";
import {Button, Modal} from "antd";
import {toJS} from "mobx";
import Mood from "./Mood"
import "./WeiboEdit.less"
import WeiboBar from "./WeiboBar";
import * as Util from "../../../../util";
const getLabel = WeaLocaleProvider.getLabel;
@inject('blogMyBlog')
class EcmeBlogDialog extends Component {
    constructor(props) {
        super(props);

        this.state={
            cubeLayoutParames:{},
            Card:{},
            isCanSave:false,
            showRich:false,
            partid:"",
            ecmeDefaultTemplate:""
        }
    }


    componentDidMount(){
    }


    initCallBack=()=>{
        const {changeEcmedilogspin} = this.props.blogMyBlog;
        changeEcmedilogspin(false);
    }


    componentWillUnmount(){

    }

    onTempletChange = (name, ids, list, type) => {

        const {getEcmeTemlate,ecmeid,changeRichOrEcme,changeEcmedilogspin,changeEcmeVisible,changeRichTextDia} = this.props.blogMyBlog;
        Modal.confirm({
            title: getLabel(505615,'替换当前内容？'),
            onOk: () => {
                if(list[0]&&list[0].contentType==1){
                    changeEcmedilogspin(true);
                    changeRichTextDia(false);
                    changeEcmeVisible(true);
                    getEcmeTemlate({templateId:list[0].id},result => {
                        changeRichOrEcme(1,result.data,result.partid)
                    })
                }else{
                    changeRichTextDia(true);
                    changeEcmeVisible(false);
                    changeRichOrEcme(0,list[0].name);
                }
            },
            onCancel: () => {

            }
        });

    }



    render(){
        const {getCardStorefun,disabled,ecmedialogspinning,changeMood,mood} = this.props;
        let cubeFlags  = Object.keys(toJS(this.props.cubeLayoutParame)).length > 0;
        const cubeLayoutParame = this.props.cubeLayoutParame;
        let {ecmeMood='1'} = this.props.blogMyBlog;

        return (

            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@yl581q`}
                title={getLabel(519584,'微博模板编辑')}
                parentClassName="ecmedialog"
                icon="icon-coms-blog"
                iconBgcolor="#6d3cf7"
                buttons={[
                    <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@qfmuazecmepublish`}  disabled={disabled} onClick={this.props.publishBlogEcme} type="primary" className="wea-wwb-publish">{getLabel(114,"发布")}</Button>,
                    <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@mh4zvd@ecmecancel`} onClick={this.props.cancelEcmeTag} type="ghost" className="wea-wwb-cancel">{getLabel(31129, "取消")}</Button>,
                ]}
				hasScroll={true}
                style={{width:720, height: 462}}
                visible={this.props.ecmevisibleDialog}
                onCancel={this.props.cancelEcmeTag}
                loading={ecmedialogspinning}
                destroyBodyOnClose={true}
            >
                <div style={{"width": "720px", "position": "fixed", "height": "50px", "margin-top":"412px", "border-top":"1px solid #e9e9e9",}}>

                    <div className="wea-ecme-item">
                        <Mood ecId={`${this && this.props && this.props.ecId || ''}_Mood@viwiir`} mooddata={{value:ecmeMood}} onSelect={mood => changeMood(mood)}/>
                    </div>
                    <div className="wea-ecme-item">
                        <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@qddb7v`}
                            customized={true}
                            type={"blogTemplate"}
                            title="模板"
                            hasAdvanceSerach={true}
                            isSingle={true}
                            onChange={this.onTempletChange}
                        >
                        <span className='wea-cbi-icon icon-blog-Task'/>
                        <span className="wea-cbi-text">  模板</span>
                        </WeaBrowser>
                    </div>

                </div>

                <div id="ecme_blogdiv" style={{"padding": "25px 0px 0px 0px"}}>
                    {cubeFlags?(CubeLayout({cubeLayoutParame,"callback":this.initCallBack,"getCardStorefun":getCardStorefun})):""}
                </div>
            </WeaDialog>

        )

    }
}

export default EcmeBlogDialog

